package com.qf.team2.netdisc.admin.service.impl;

import com.qf.team2.netdisc.admin.dao.AdminMapper;
import com.qf.team2.netdisc.admin.service.AdminLoginService;
import com.qf.team2.netdisc.common.exception.BusinessException;
import com.qf.team2.netdisc.common.pojo.entity.User;
import com.qf.team2.netdisc.common.util.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 管理员登录服务接口实现类
 *
 * @author Simon_Wong
 * @date 2021/05/26 14:52
 * @since 2021/5/26 14:52
 */
@Service
public class AdminLoginServiceImpl implements AdminLoginService {

    @Autowired
    private AdminMapper adminMapper;

    @Override
    public User login(String username, String password) {
        User dbUser = adminMapper.selectAdminByUsername(username);
        if (null == dbUser) {
            throw new BusinessException("无此管理员帐号");
        }
        if (!MD5Util.md5(password).equals(dbUser.getPassword())) {
            throw new BusinessException("密码错误");
        }
        dbUser.setPassword("");
        return dbUser;
    }
}
